//
//  HSNetwordTools.swift
//  HomeSchoolDemo
//
//  Created by rimi on 16/9/29.
//  Copyright © 2016年 赖虹宇. All rights reserved.
//

import UIKit
import AFNetworking

class HSNetwordTools: AFHTTPSessionManager {
    ///创建单例--- Swift单例写法
    static let shared:HSNetwordTools = {
        //初始化工具类实例
        let instance = HSNetwordTools(baseURL: URL(string: baseURLStr ?? ""))
        //调整AFN的数据解析格式(增加解析数据的格式)
        instance.responseSerializer.acceptableContentTypes?.insert("text/html")
        return instance
    }()
    
    //网络请求方法
    func downloadData(urlStr:String,parameters:Any?,dataCallBack:@escaping (_ data:Any?,_ error:Error?) -> ())  {
        get(urlStr, parameters: parameters, progress: nil, success: { (_, data) in
            //闭包回调参数
            dataCallBack(data, nil)
        }) { (_, error) in
            dataCallBack(nil, error)
        }
    }
}
